www.mxdraw.com
内容索引主面
前一个向上下一个
IMxDrawSelectionSet::Select 方法

构造选择集

IDL
[helpstring("method Select")]
HRESULT Select([in] MCAD_McSelect Mode, [in] IMxDrawPoint* point1, [in] IMxDrawPoint* point2, [in,defaultvalue(NULL)] IMxDrawResbuf* filterData);
参数 
说明 
[in] MCAD_McSelect Mode 
构造选择集方式 
[in] IMxDrawPoint* point1 
构造择择集时需要使用到的点对象 
[in] IMxDrawPoint* point2 
构造择择集时需要使用到的点对象 
[in,defaultvalue(NULL)] IMxDrawResbuf* filterData 
构造选择集的过滤数据 
可以取如下值 
mcSelectionSetWindow = 0, mcSelectionSetCrossing = 1, mcSelectionSetFence = 2, mcSelectionSetPrevious = 3, mcSelectionSetLast = 4, mcSelectionSetAll = 5, 选择图面上的所有实体 mcSelectionSetWindowPolygon = 6, mcSelectionSetCrossingPolygon = 7, mcSelectionSetUserSelect = 8 mcSelectionImpliedSelectSelect = 9,_I 返回当前图上已经选择的实体 

例如: 得到图上所有的实体,js语言代码

        function GetAllEntity() {
        var ss;
        ss = new ActiveXObject("MxDrawX.MxDrawSelectionSet");
        ss.Select(5);

        var i = 0;
        for (; i < ss.Count; i++)
        {
            var ent = ss.Item(i);
            if (ent.ObjectName == "McDbLine") {
                alert("直线");
            }
            else {
                alert(ent.ObjectName);
            }

        }

       }

例如: 得到当前已经选择的实体,Delphi代码

    procedure TForm1.Button1Click(Sender: TObject);
    var
      ss              :  IMxDrawSelectionSet;
      ii,iNum         : Integer;
      pEnt            : IMxDrawEntity;
    begin
             iNum := 0;
             ss :=  CoMxDrawSelectionSet.Create();


             ss.Select(9,EmptyParam,EmptyParam,EmptyParam,EmptyParam);

             // 遍历选择集实体,
             for ii := 0 to ss.Count -1 do
             begin
                  pEnt := ss.Item(ii);
                  iNum := iNum + 1;
             end;
             showmessage('当前选择了' + IntToStr(iNum) + '个对象');
    end;

例如: VB 带过滤条件构选择集,下面代码,得到0层上所有实体

        '设置过滤条变量
        Dim filter As MxDrawResbuf
        Set filter = New MxDrawResbuf
        '把图层名"0"作为过滤条件
        filter.AddString "0", 8

        '定义选择集对象
        Dim ss As MxDrawSelectionSet
        Set ss = New MxDrawSelectionSet

        '选择图上的所有实体,过滤条为filter
        ss.Select 5, , , , filter

        ' 遍历选择集中的实体
        Dim i As Integer

        i = 0
        Do While i < ss.Count
            Dim ent As MxDrawEntity
            Set ent = ss.Item(i)
            MsgBox ent.Layer
            i = i + 1
        Loop

 

例如: JS,与用户选择对象.

            function CreateGroup() {
                mxOcx.Prompt("选择要做成组的实体:");
                var ss = mxOcx.NewSelectionSet();

                ss.Select2(8, null, null, null);
                var param = mxOcx.NewResbuf();

                for(var i = 0; i < ss.Count;i++)
                {
                    var ent = ss.Item(i);
                    if(ent == null)
                        continue;

                    param.AddObjectId(ent.ObjectID);
                }
                if(param.Count == 0)
                    return;
                mxOcx.CreateGroup("", param);

            }

例如: C#计算鼠标点位置的闭合pl线的面积.

    private void axMxDrawX1_MouseEvent(object sender, AxMxDrawXLib._DMxDrawXEvents_MouseEventEvent e)
            {
                if (e.lType == 4)
                {
                    // 是鼠标左键双击

                    // 得到鼠标位置
         
                    MxDrawPoint point = new MxDrawPoint();
                    point.x = e.dX;
                    point.y = e.dY;

                    // 构造择集,得到鼠标所在闭合区域。

                    // 设置过滤条件
                    MxDrawResbuf filter = new MxDrawResbuf();

                    // 设置PL线为过滤条件
                    filter.AddStringEx("LWPOLYLINE", 5020);

                    // 选择范围左下角

                    MxDrawPoint pt1 = new MxDrawPoint();
                    pt1.x = point.x - 100;
                    pt1.y = point.y - 100;


                    // 选择范围右上角

                    MxDrawPoint pt2 = new MxDrawPoint();
                    pt2.x = point.x + 100;
                    pt2.y = point.y + 100;



                    // 选择pt1,pt2所在范围内的对象.
                    MxDrawSelectionSet ss = new MxDrawSelectionSet();
                    ss.Select(MCAD_McSelect.mcSelectionSetCrossing, pt1, pt2, filter);

                    for (int i = 0; i < ss.Count; i++)
                    {
                        // 遍历所有对象,看当前点是在那个闭合区域内

                        MxDrawPolyline pl = (MxDrawPolyline)ss.Item(i);

                        // 得到闭合区域的点坐标。

                        MxDrawPoints pts = new MxDrawPoints();
                        for (int j = 0; j < pl.NumVerts; j++)
                        {
                            MxDrawPoint pt = pl.GetPointAt(j);
                            pts.Add(pt.x, pt.y, pt.z);
                        }

                        if (pts.Count < 3)
                            continue;

                        // 判断鼠标点,是不是在这个闭合的区域内.

                        MxDrawUtility utility = new MxDrawUtility();
                        if (utility.PointInPolyline(pts, point.x, point.y))
                        {
                            // 找到用户点击的闭合区域 
                            double dArea = 0.0;
                            pl.GetArea(out dArea);

                            // 对选择的区域填充

                            for (int k = 0; k < pts.Count; k++)
                            {
                                MxDrawPoint tmp = pts.Item(k);
                                if(k == 0)
                                    axMxDrawX1.PathMoveTo(tmp.x, tmp.y);
                                else
                                    axMxDrawX1.PathLineTo(tmp.x, tmp.y);
                            }

                            axMxDrawX1.DrawCADColorIndex = 3;
                            axMxDrawX1.DrawPathToHatch(0.0);
                            axMxDrawX1.UpdateDisplay();

                                MessageBox.Show("面积为:" + dArea.ToString());

                            e.lRet = 1;
                            // 取消后面的命令。
                            axMxDrawX1.SendStringToExecute("");

                            break;
                        }
                    }

                }
            }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!